//package cn.com.shaom.learning.sb.security.example2.config;
//
//import cn.com.shaom.learning.sb.security.example2.service.CumMethodSecurityExpression;
//import cn.com.shaom.learning.sb.security.example2.service.CumPermissionEvaluator;
//import org.aopalliance.intercept.MethodInvocation;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.access.PermissionEvaluator;
//import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
//import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;
//import org.springframework.security.access.expression.method.MethodSecurityExpressionOperations;
//import org.springframework.security.authentication.AuthenticationTrustResolver;
//import org.springframework.security.authentication.AuthenticationTrustResolverImpl;
//import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
//import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
//import org.springframework.security.core.Authentication;
//
///**
// * @author Shaom
// */
//@Configuration
//@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
//public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {
//    @Bean
//    public PermissionEvaluator cumPermissionEvaluator() {
//        return new CumPermissionEvaluator();
//    }
//
//    @Override
//    protected MethodSecurityExpressionHandler createExpressionHandler() {
//        // 配置自定义的表达是，不然直接使用 DefaultMethodSecurityExpressionHandler 即可
//        CustomMethodSecurityExpressionHandler expressionHandler = new CustomMethodSecurityExpressionHandler();
//        expressionHandler.setPermissionEvaluator(new CumPermissionEvaluator());
//        return expressionHandler;
//    }
//
//    /**
//     * 配置自定义的表达式
//     */
//    class CustomMethodSecurityExpressionHandler extends DefaultMethodSecurityExpressionHandler {
//        private AuthenticationTrustResolver trustResolver = new AuthenticationTrustResolverImpl();
//
//        @Override
//        protected MethodSecurityExpressionOperations createSecurityExpressionRoot(Authentication authentication, MethodInvocation invocation) {
//
//            CumMethodSecurityExpression root = new CumMethodSecurityExpression(authentication);
//
//            root.setPermissionEvaluator(getPermissionEvaluator());
//            root.setTrustResolver(this.trustResolver);
//            root.setRoleHierarchy(getRoleHierarchy());
//
//            return root;
//
//        }
//    }
//}